from typing import Any, Optional, TypeVar

from zkl_registries.basics import TagKey

VT = TypeVar('VT')


class ObjTagKey(TagKey[Optional[VT], Any, Optional[int]]):
    def __init__(self, name: str, *, strict: bool, required: bool):
        self._name = name
        self._strict = strict
        self._required = required

    @property
    def name(self) -> str:
        return self._name

    def match(self, query: Optional[Any], val: Optional[VT]) -> Optional[int]:
        if query is None:
            if val is None:
                return 2
            if not self._required:
                return 1
            return None

        if val is None:
            if not self._strict:
                return 2
            return None

        if query == val:
            return 3
        return None
